import {observable as o, computed as c, action as a} from 'mobx';
import _ from 'lodash';
import axios from 'core/axios';
import RootStore from 'core/Store.js';
import request from 'core/request.js';
import Im from 'immutable';
import {browserHistory} from 'react-router';

class Store extends RootStore {
    constructor(args) {
        super(args);
    }

    will() {

    }

    @o visible = false;
    @o sortNum = '';
    // @o id = '';
    @o confirmFunc = null;

    @a
    sortChange(v) {
        this.sortNum = v || '';
    }

    @a
    closeDialog(e) {
        e.preventDefault();
        e.stopPropagation();
        this.setToDefault();
    }

    @a
    setToDefault() {
        this.visible = false;
        this.sortNum = '';
        this.confirmFunc = null;
    }

    @a
    confirmDialog() {
        if (!this.sortNum) {
            this.stores.Message.showMessage(3, '请填写排序顺序');
            return;
        }
        if (typeof this.confirmFunc === 'function') {
            this.confirmFunc(this.sortNum);
            this.visible = false;
        }
    }


    mount() {
        this.on('sortDialog:show', (data) => {
            this.visible = true;
            this.sortNum = data.sort;
            this.confirmFunc = data.confirmFunc || null;
            // this.id = data.detail.id;
        });
        browserHistory.listen(() => {
            if (this.visible) {
                this.setToDefault()
            }
        });
    }

}

export default Store;